36c0b13147bd11124d5e36095c97a90fbbc32ea9,NoHttp/src/com/yolanda/nohttp/download/DownloadConnection.java,DownloadConnection,download,#number#DownloadRequest#DownloadListener#,79

Before Change


				}
			}
			if (downloadRequest.isCanceled()) {
				downloadRequest.takeQueue(false);
				Log.i("NoHttpDownloader", "Download request is canceled");
				downloadListener.onCancel(what);
				return;

After Change


			} else if (responseCode == 200) {
				totalLength = httpConnection.getContentLength();// 直接下载
			} else {
				downloadRequest.getAnalyzeReqeust().takeQueue(false);
				downloadListener.onDownloadError(what, StatusCode.ERROR_OTHER, "Server responseCode error: " + responseCode);
				return;
			}

			// �存空间判断
			if (FileUtil.getDirSize(downloadRequest.getFileDir()) < totalLength) {
				downloadRequest.getAnalyzeReqeust().takeQueue(false);
				downloadListener.onDownloadError(what, StatusCode.ERROR_STORAGE_NOT_ENOUGH, "Specify the location, save space");
				return;
			}
			// 通知开始下载了
			Logger.d("-------Download start-------");
			downloadListener.onStart(what, tempFileLength > 0, tempFileLength, Headers.parseMultimap(responseHeaders), totalLength);
			inputStream = httpConnection.getInputStream();
			String contentEncoding = httpConnection.getContentEncoding();
			if (HeaderParser.isGzipContent(contentEncoding))
				inputStream = new GZIPInputStream(inputStream);

			RandomAccessFile randomAccessFile = new RandomAccessFile(tempFile, "rw");
			randomAccessFile.seek(tempFileLength);

			byte[] buffer = new byte[1024];
			int len = 0;

			int oldProgress = 0;// 旧的进度记录,防止��通知
			long count = tempFileLength;// 追加目�已�下载的进度

			while (((len = inputStream.read(buffer)) != -1)) {
				if (downloadRequest.isCanceled()) {
					downloadRequest.getAnalyzeReqeust().takeQueue(false);
					Log.i("NoHttpDownloader", "Download request is canceled");
					downloadListener.onCancel(what);
					break;
				} else {
					randomAccessFile.write(buffer, 0, len);
					count += len;
					if (totalLength != 0) {
						int progress = (int) (count * 100 / totalLength);
						if ((0 == progress % 2 || 0 == progress % 3 || 0 == progress % 5 || 0 == progress % 7) && oldProgress != progress) {
							oldProgress = progress;
							downloadListener.onProgress(what, oldProgress, count);// 进度通知
						}
					}
				}
			}
			randomAccessFile.close();
			if (!downloadRequest.isCanceled()) {
				downloadRequest.getAnalyzeReqeust().takeQueue(false);
				tempFile.renameTo(lastFile);
				Logger.d("-------Donwload finish-------");
				downloadListener.onFinish(what, lastFile.getAbsolutePath());